using System;
using System.Configuration;

namespace eBenefits.Web.Helpers
{
	/// <summary>
	/// A class for helping to fetch certain settings that are commonly used.
	/// </summary>
	public sealed class SettingsHelper
	{
		private SettingsHelper() {}
		
		#region GetDbConnectionString
		public static string GetDbConnectionString()
		{
			return GetDbConnectionString("ApplicationServices");
		}
		
		public static string GetDbConnectionString (string connectionName)
		{
			string connectionString = string.Empty;
			
			if (ConfigurationManager.ConnectionStrings[connectionName] != null)
				connectionString = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;
			
			return connectionString;
		}
		#endregion GetDbConnectionString

		#region Theme-related
		/// <summary>
		/// <add key="Themes_Folder" value="~/Content/Themes"/>
		/// </summary>
		public static string ThemeFolder
		{
			get
			{
				return ConfigurationManager.AppSettings["Themes_Folder"];
			}
		}
		
		/// <summary>
		/// <add key="Default_Theme" value="NewHorizon11"/>
		/// </summary>
		public static string DefaultThemeName
		{
			get
			{
				return ConfigurationManager.AppSettings["Default_Theme"];
			}
		}
		
		/// <summary>
		/// <add key="Theme_Cookie_Name" value="Preferred_eBenefits_Theme"/>
		/// </summary>
		public static string ThemeCookieName
		{
			get
			{
				return ConfigurationManager.AppSettings["Theme_Cookie_Name"];
			}
		}
		
		/// <summary>
		/// <add key="Theme_Session_Name" value="Preferred_eBenefits_Theme"/>
		/// </summary>
		public static string ThemeSessionName
		{
			get
			{
				return ConfigurationManager.AppSettings["Theme_Session_Name"];
			}
		}
		#endregion Theme-related
		
		#region Culture-related
		/// <summary>
		/// <add key="Default_Culture" value="en"/>
		/// </summary>
		public static string DefaultCultureName 
		{
			get { return ConfigurationManager.AppSettings["Default_Culture"]; }
		}
		
		/// <summary>
		/// <add key="Culture_Cookie_Name" value="Preferred_eBenefits_Culture"/>
		/// </summary>
		public static string CultureCookieName 
		{
			get { return ConfigurationManager.AppSettings["Culture_Cookie_Name"]; }
		}
		
		/// <summary>
		/// <add key="Culture_Session_Name" value="Preferred_eBenefits_Culture"/>
		/// </summary>
		public static string CultureSessionName 
		{
			get { return ConfigurationManager.AppSettings["Culture_Session_Name"]; }
		}
		#endregion Culture-related
		
		#region Cookies-related
		/// <summary>
		/// <add key="Always_Use_Secure_Cookies" value="false"/>
		/// </summary>
		public static bool UseSecureCookies
		{
			get
			{
				bool result = false;
				if (!bool.TryParse (ConfigurationManager.AppSettings["Always_Use_Secure_Cookies"], out result))
					throw new Exception ("Unable to determine UseSecureCookies");
				
				return result;
			}
		}
		
		/// <summary>
		/// <add key="Always_Use_HttpOnly_Cookies" value="true"/>
		/// </summary>
		public static bool UseHttpOnlyCookies {
			get {
				bool result = false;
				if (!bool.TryParse (ConfigurationManager.AppSettings["Always_Use_HttpOnly_Cookies"], out result))
					throw new Exception ("Unable to determine UseHttpOnlyCookies");
				
				return result;
			}
		}
		
		#endregion Cookies-related
		
		public static string LogsFolder 
		{
			get { return ConfigurationManager.AppSettings["Logs_Folder"]; }
		}
		
	} // [End-of-class]
} // [End-of-namespace]

